package com.coldwindblows.blog.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.coldwindblows.blog.dao.RelationshipMapper;
import com.coldwindblows.blog.pojo.RelationshipDo;
import com.coldwindblows.blog.service.IRelationshipService;

/**
 * Created by ColdWindBlows on 2018/07/04
 */
@Service
public class IRelationshipServiceImpl implements IRelationshipService {
	
	@Autowired
	private RelationshipMapper relationshipDao;
	
	/**
	 * 删除条件 cid 和 mid 不能同时为空
	 */
	@Override
	public boolean deleteById(Integer cid, Integer mid) {
		if(cid == null && mid == null) { 
			return false;
		}
		RelationshipDo rdo = new RelationshipDo();
		rdo.setCid(cid);
		rdo.setMid(mid);
		int result = relationshipDao.deleteByCidAndMid(rdo);
		System.out.println(result);
		return result > 0;
	}

	@Override
	public Long countById(Integer cid, Integer mid) {
		RelationshipDo rdo = new RelationshipDo();
		rdo.setCid(cid);
		rdo.setMid(mid);
		
		return relationshipDao.countByCidAndMid(rdo);
	}

	@Override
	public boolean insert(RelationshipDo relationshipKey) {
		return relationshipDao.insert(relationshipKey) > 0;
	}

	@Override
	public List<RelationshipDo> getRelationshipById(Integer cid, Integer mid) {
		RelationshipDo temp = new RelationshipDo();
		temp.setCid(cid);
		temp.setMid(mid);
		
		return relationshipDao.selectByCidAndMid(temp);
	}

}
